﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MyBBS.Data.Extensions
{
    public static class DateTimeExtension
    {
        public static string Ago(this DateTime target)
        {
            var result = new StringBuilder();
            TimeSpan diff = (DateTime.Now - target.ToLocalTime());

            if (diff.Days > 0)
            {
                result.AppendFormat("{0} days", diff.Days);
            }
            else
            {
                if (diff.Hours > 0)
                {
                    if (result.Length > 0)
                    {
                        result.Append(", ");
                    }

                    result.AppendFormat("{0} hours", diff.Hours);
                }

                if (diff.Minutes > 0)
                {
                    if (result.Length > 0)
                    {
                        result.Append(", ");
                    }

                    result.AppendFormat("{0} minutes", diff.Minutes);
                }
            }
            if (result.Length == 0)
            {
                result.Append("few moments");
            }

            result.Append(" ago");
            return result.ToString();
        }
    }
}
